/**
 *====================================================
 * 文件名称: FeedbackActionApiImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年12月7日			chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.news.action.v1;

import java.util.Date;

import com.yuexunit.core.BusinessException;
import com.yuexunit.finance.common.httpclient.HttpClientHelper;
import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.context.FinanceSessionContext;
import com.yuexunit.finance.member.entity.EnterpriseEntity;
import com.yuexunit.finance.news.action.v1.dto.FeedbackCastor;
import com.yuexunit.finance.project.action.v1.model.output.FeedbackDetail;
import com.yuexunit.finance.project.entity.FinanceFeedbackEntity;
import com.yuexunit.finance.project.service.FinanceFeedbackService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.util.StringUtil;
import com.yuexunit.web.spi.SessionContext;

import antlr.StringUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: FeedbackActionApiImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年12月7日 下午8:21:52
 */
@Implements(FinanceFeedbackActionApi.class)
public class FinanceFeedbackActionApiImpl implements FinanceFeedbackActionApi {

	private FinanceFeedbackService feedbackService = ComponentFactory.loadClass(FinanceFeedbackService.class);

	@Override
	public String createFeedback(String content, String fileUuid) {
		FinanceFeedbackEntity entity = new FinanceFeedbackEntity();
		entity.setContent(content);
		entity.setFileUuid(fileUuid);
		if(SessionContext.getExtra() != null){
			entity.setAccount(FinanceSessionContext.getAccountFullName());
			entity.setAccountId(FinanceSessionContext.getAccountId());
		}
		return feedbackService.createFeedback(entity).toString();
	}
	
	@Override
	public FeedbackDetail inquireFeedbackDetail(Long feedbackId) {
		FinanceFeedbackEntity feedback = feedbackService.inquireFeedback(feedbackId);
		return FeedbackCastor.toFeedbackDetail(feedback);
	}

	@Override
	public PageList<FeedbackDetail> inquireSelfFeedbackPageList(String content, String dateBegin, String dateEnd, PageCriteria page) {
		Long accountId = FinanceSessionContext.getAccountId();
		Date beginDateTime = DateUtils.formatBeginDay(dateBegin);
		Date endDateTime = DateUtils.formatBeginDay(dateEnd);
		PageList<FinanceFeedbackEntity> pages = feedbackService.inquireFeedbackPageList(content, accountId, beginDateTime, endDateTime, page);
		PageList<FeedbackDetail> results = new PageList<>(page, pages.getTotalRecordCount());
		for (FinanceFeedbackEntity entity : pages) {
			results.add(FeedbackCastor.toFeedbackDetail(entity));
		}
		return results;
	}

	@Override
	public PageList<FeedbackDetail> inquireFeedbackPageList(String content, String dateBegin, String dateEnd, PageCriteria page) {
		Date beginDateTime = DateUtils.formatBeginDay(dateBegin);
		Date endDateTime = DateUtils.formatBeginDay(dateEnd);
		PageList<FinanceFeedbackEntity> pages = feedbackService.inquireFeedbackPageList(content, null, beginDateTime, endDateTime, page);
		PageList<FeedbackDetail> results = new PageList<>(page, pages.getTotalRecordCount());
		for (FinanceFeedbackEntity entity : pages) {
			results.add(FeedbackCastor.toFeedbackDetail(entity));
		}
		return results;
	}

}
